<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/xml; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@page import="net.groupme.api.API_CONSTANTS"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.List"%>
<%@page import="net.groupme.model.Resource"%>


<%@page import="net.groupme.model.Tag"%>
<%@page import="net.groupme.model.MODEL_CONSTANTS"%>
<%@page import="net.groupme.model.Group"%>
<%@page import="net.groupme.model.ObjectFactory"%>
<%@page import="java.net.URLEncoder"%>
<result query="<%= request.getAttribute(API_CONSTANTS.OBJECT_QUERY).toString() %>" time="<%= new Date().toString() %>">
<% 
	List<Resource> result = (List<Resource>) request.getAttribute(API_CONSTANTS.OBJECT_RESULT_LIST); 
	Resource resource = null;
	Integer offset = (Integer)request.getAttribute(API_CONSTANTS.OBJECT_OFFSET);
	for(int rank = 0; rank<result.size(); rank++){
		resource = result.get(rank);
%>
	<resource 
		rank="<%= rank + offset + 1 %>" 
		uri="<%= resource.getURI() %>"
		<%	
			if(!MODEL_CONSTANTS.RESOURCE_TYPE_GROUP.equals(resource.getType())){
		%>
			weburl="<%= resource.getURL().toString().replaceAll("&", "&amp;") %>"
		<%	} %>
		name="<%= resource.getName() %>" 
		<% 	String description = resource.getDescription();
			if(description == null){
				description = "no description";
			}
			description = description.replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("&", "&amp;");
			%>
		description="<%=  description %>" 
		type="<%= resource.getType() %>" >
		
		<%	for(Tag tag: resource.getTags()){ %>
				<hasTag tag="<%= tag.getKeyword() %>"/>	
		<%	} %>
		
		<%	
			if(MODEL_CONSTANTS.RESOURCE_TYPE_GROUP.equals(resource.getType())){
				for(Resource member: ObjectFactory.getGroup(resource.getURI()).getResources()){ %>
					<hasResource 
						uri="<%= member.getURI() %>"
						<%	
						if(!MODEL_CONSTANTS.RESOURCE_TYPE_GROUP.equals(member.getType())){
						%>
							weburl="<%= member.getURL().toString().replaceAll("&", "&amp;") %>"
					<%	} %>
						name="<%= member.getName() %>" 
						type="<%= member.getType() %>" />	
			<%	} %>	
		<%	} %>
	</resource>
<%
	}
%>
</result>